#include "entity.h"
#include "vector3.hpp"

Entity::Entity(float mass, Vector3* position, Vector3* initForce) : mass(mass), position(position), initForce(initForce)
{
	lifeTime = 0.0f;

	accumForce = new Vector3();
	velocity = new Vector3();
}

float Entity::LifeTime()
{
	return lifeTime;
}

float Entity::Mass()
{
	return mass;
}

Vector3* Entity::AccumForce()
{
	return accumForce;
}

Vector3* Entity::InitForce()
{
	return initForce;
}

Vector3* Entity::Position()
{
	return position;
}

Vector3* Entity::Velocity()
{
	return velocity;
}

void Entity::AddForce(Vector3& frc)
{
	(*accumForce) += frc;
}

void Entity::Init()
{
	(*accumForce) += (*initForce);
}

void Entity::Reset()
{
	accumForce->Zero();
	initForce->Zero();
	velocity->Zero();
}

void Entity::Invert(Axis axis)
{
	accumForce->Invert(axis);
	initForce->Invert(axis);
	velocity->Invert(axis);
	
}

void Entity::ReduceForce()
{
	/*accumForce->x =  accumForce->x * -0.7;
	accumForce->y  = accumForce->y * -0.7;*/
	velocity->y = velocity->y * 0.7f;
	velocity->x = velocity->x * 0.7f;
}

void Entity::Update(float time)
{
	//Update position and velocity
	position = *position + *((*velocity) * time);

	acceleration = (*accumForce) / mass;
	*acceleration *= time;
	velocity = (*velocity) + (*acceleration);

	lifeTime += time;
	if(lifeTime > 2)
	{
		this->initForce->Zero();
	}
}